

package com.sihai.gateway.route;

import cn.hutool.core.util.ArrayUtil;
import com.sihai.gateway.core.route.RouteDefinition;
import com.sihai.gateway.core.route.RouteInitializer;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

/**
 * @author sihai
 */
@RequiredArgsConstructor
public class DefaultRouteInitializer implements RouteInitializer {

  private final RouteDefinitionLocator routeDefinitionLocator;

  @Override
  public void initialize(List<RouteDefinition> routeDefinitions) {
    if (!CollectionUtils.isEmpty(routeDefinitions)) {
      routeDefinitionLocator.saveRoutes(ArrayUtil.toArray(routeDefinitions, RouteDefinition.class));
    }
  }
}
